{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Student Attendance Record I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: checkRecord"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #学生出勤记录 I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串 <code>s</code> 表示一个学生的出勤记录，其中的每个字符用来标记当天的出勤情况（缺勤、迟到、到场）。记录中只含下面三种字符：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>'A'</code>：Absent，缺勤</li>\n",
    "\t<li><code>'L'</code>：Late，迟到</li>\n",
    "\t<li><code>'P'</code>：Present，到场</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果学生能够 <strong>同时</strong> 满足下面两个条件，则可以获得出勤奖励：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>按 <strong>总出勤</strong> 计，学生缺勤（<code>'A'</code>）<strong>严格</strong> 少于两天。</li>\n",
    "\t<li>学生 <strong>不会</strong> 存在 <strong>连续</strong> 3 天或 <strong>连续</strong> 3 天以上的迟到（<code>'L'</code>）记录。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果学生可以获得出勤奖励，返回 <code>true</code> ；否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"PPALLP\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>学生缺勤次数少于 2 次，且不存在 3 天或以上的连续迟到记录。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"PPALLL\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>学生最后三天连续迟到，所以不满足出勤奖励的条件。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 1000</code></li>\n",
    "\t<li><code>s[i]</code> 为 <code>'A'</code>、<code>'L'</code> 或 <code>'P'</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [student-attendance-record-i](https://leetcode.cn/problems/student-attendance-record-i/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [student-attendance-record-i](https://leetcode.cn/problems/student-attendance-record-i/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"PPALLP\"', '\"PPALLL\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A') >= 2:\n",
    "            return False\n",
    "        if 'LLL' in s:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absents=lates=0\n",
    "        #枚举的意思，把s字符串里面的字符存入i和c,i存储的是下标，c存储的是字母\n",
    "        for i,c in enumerate(s):\n",
    "            if c ==\"A\":\n",
    "                absents+=1\n",
    "                if absents>=2:\n",
    "                    return False\n",
    "            if c==\"L\":\n",
    "                lates+=1\n",
    "                if lates>=3:\n",
    "                    return False\n",
    "            else:\n",
    "                    lates=0\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        n = \"PPALLL\"\n",
    "        ii = 'LLL'\n",
    "        if ii not in s and s.count('A')<2:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and not 'LLL' in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A')<2 and 'LLL' not in s:\n",
    "            return True\n",
    "        else: return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and (\"LLL\" not in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.find('LLL') == -1 and s.count('A') < 2:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if \"LLL\" in s:\n",
    "            return False\n",
    "        s_list = list(s)\n",
    "        if s_list.count('A') >= 2:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "\n",
    "        if s.count('A')>=2:\n",
    "            return False    \n",
    "        elif 'LLL' in s:   \n",
    "            return False    \n",
    "        else:\n",
    "            return True    \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and s.find('LLL')<0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return False if 'LLL'in s or s.count('A')>1 else True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        A_count = s.count('A')\n",
    "        if A_count >= 2:\n",
    "            return False\n",
    "        L_count = 0\n",
    "        for str in s:\n",
    "            if str != 'L':\n",
    "                if L_count >= 3:\n",
    "                    return False\n",
    "                L_count = 0\n",
    "            else:\n",
    "                L_count += 1\n",
    "        if L_count >= 3:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent_count = 0\n",
    "        late_count = 0\n",
    "\n",
    "        for record in s:\n",
    "            if record == 'A':\n",
    "                absent_count += 1\n",
    "                late_count = 0\n",
    "                if absent_count >= 2:\n",
    "                    return False\n",
    "            elif record == 'L':\n",
    "                late_count += 1\n",
    "                if late_count >= 3:\n",
    "                    return False\n",
    "            else:\n",
    "                late_count = 0\n",
    "\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        late = 0\n",
    "        absent = 0\n",
    "        for i in s:\n",
    "            if i==\"A\":\n",
    "                absent+=1\n",
    "                late=0\n",
    "            elif i==\"L\":\n",
    "                late+=1\n",
    "                if late>=3:\n",
    "                    return False\n",
    "            else:\n",
    "                late=0\n",
    "        return True if absent<2 else False\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        latecount=0\n",
    "        absentcount=0\n",
    "        arr=list(s)\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i]=='A':\n",
    "                absentcount+=1\n",
    "            if i<=len(arr)-3 and arr[i]==arr[i+1]==arr[i+2]=='L':\n",
    "                latecount+=3\n",
    "        if absentcount<2 and latecount<3:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return 'LLL' not in s and s.count('A') < 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') <= 1 and \"LLL\" not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return True if \"LLL\" not in s and s.count(\"A\") < 2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and s.find('LLL') == -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        cnt_a=0\n",
    "        c_cnt_l=0\n",
    "        last_ch=''\n",
    "        for ch in s:\n",
    "            if ch=='A':\n",
    "                cnt_a+=1\n",
    "                if cnt_a>=2:\n",
    "                    return False\n",
    "            elif ch=='L':\n",
    "                if last_ch=='L':\n",
    "                    c_cnt_l+=1\n",
    "                    if c_cnt_l>=3:\n",
    "                        return False\n",
    "                else:\n",
    "                    c_cnt_l=1\n",
    "            last_ch=ch\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A')<2 and 'LLL' not in s:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        late_count = 0\n",
    "\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                absent += 1\n",
    "                late_count = 0\n",
    "            elif i == 'L':\n",
    "                late_count += 1\n",
    "            elif late_count != 0:\n",
    "                late_count =0\n",
    "            \n",
    "            if absent == 2 or late_count == 3:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and 'LLL' not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        countCharacters={}\n",
    "        for i in s:\n",
    "            if i not in countCharacters:\n",
    "                countCharacters[i]=1\n",
    "            else:\n",
    "                countCharacters[i]+=1\n",
    "        if \"A\" not in s and \"LLL\" not in s:\n",
    "            return True\n",
    "        elif \"A\" in s and countCharacters[\"A\"]<2 and \"LLL\" not in s:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        cntA = cntL = 0\n",
    "        for x in s:\n",
    "            match x:\n",
    "                case 'A':\n",
    "                    cntA += 1\n",
    "                    if cntA == 2:\n",
    "                        return False\n",
    "                    cntL = 0\n",
    "                case 'L':\n",
    "                    cntL += 1\n",
    "                    if cntL == 3:\n",
    "                        return False\n",
    "                case _:\n",
    "                    cntL = 0\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A') < 2 and 'LLL' not in s:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s):\n",
    "        return 'LLL' not in s and s.count('A') < 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if(s.count('A') >= 2):\n",
    "            return False\n",
    "        if(s.count(\"LLL\") != 0):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if(s.count('A') >= 2):\n",
    "            return False\n",
    "        if(s.count(\"LLL\") != 0):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and ( 'LLL' not in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        cnt = Counter(s)\n",
    "        return cnt['A'] < 2 and 'LLL' not in s\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and 'LLL' not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and s.count('LLL') ==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return not 'LLL' in s and s.count('A') < 2\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        abscnt = 0\n",
    "        for i in range(len(s)):\n",
    "            if s[i] =='A':\n",
    "                abscnt +=1\n",
    "                if abscnt >=2:\n",
    "                    return False\n",
    "            elif s[i] =='L':\n",
    "                if i-1>=0 and i+1<len(s): \n",
    "                    if s[i-1] =='L' and s[i+1] =='L':\n",
    "                        return False \n",
    "        return True                  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def checkRecord(self, s: str) -> bool:\r\n",
    "        return self.valid2A(s) and self.valid3L(s)\r\n",
    "        \r\n",
    "    def valid2A(self,s : str):\r\n",
    "        count = 0\r\n",
    "        for c in s:\r\n",
    "            if c == 'A':\r\n",
    "                count += 1\r\n",
    "        return count < 2\r\n",
    "\r\n",
    "    def valid3L(self,s : str):\r\n",
    "        if s.find('LLL') == -1 :\r\n",
    "            return True\r\n",
    "        else:\r\n",
    "            return False\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A') >= 2:\n",
    "            return False\n",
    "        for day in range(0,len(s)-2):\n",
    "            if s[day:day+3] == 'LLL':\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        #return s.count('A')<2 and not 'LLL' in s\n",
    "        #计数枚举\n",
    "        absents=lates=0\n",
    "        for i,num in enumerate(s):\n",
    "            if num=='A':\n",
    "                absents+=1\n",
    "                if absents>=2:\n",
    "                    return False\n",
    "            if num=='L':\n",
    "                lates+=1\n",
    "                if lates>=3:\n",
    "                    return False\n",
    "            else:#如果不是连续三天L就置0\n",
    "                lates=0\n",
    "        return True\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and not 'LLL' in s\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if(s.count('A') < 2 and s.count(\"LLL\") == 0):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution():\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        absent = 0\n",
    "        if s.count('A') >= 2:\n",
    "            return False\n",
    "        if 'LLL' in s:\n",
    "            return False\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        late_count = 0\n",
    "\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                absent += 1\n",
    "                late_count = 0\n",
    "            elif i == 'L':\n",
    "                late_count += 1\n",
    "            elif late_count != 0:\n",
    "                late_count =0\n",
    "            \n",
    "            if absent == 2 or late_count == 3:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        late_count = 0\n",
    "\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                absent += 1\n",
    "                late_count = 0\n",
    "            elif i == 'L':\n",
    "                late_count += 1\n",
    "            elif late_count != 0:\n",
    "                late_count =0\n",
    "            \n",
    "            if absent == 2 or late_count == 3:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent,late = 0,0\n",
    "        for i,c in enumerate(s):\n",
    "            if c=='A':\n",
    "                absent += 1\n",
    "                if absent >= 2:\n",
    "                    return False\n",
    "            if c=='L':\n",
    "                late += 1\n",
    "                if late >= 3:\n",
    "                    return False\n",
    "            else:\n",
    "                late = 0\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if 'LLL' in s:\n",
    "            return False\n",
    "        elif s.count('A')>=2:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A') >= 2:\n",
    "            return False\n",
    "        else:\n",
    "            flg = 0\n",
    "            for i in s:\n",
    "                if i == 'L':\n",
    "                    flg += 1\n",
    "                    if flg >= 3:\n",
    "                        return False\n",
    "                else:\n",
    "                    flg = 0\n",
    "            return True \n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        d = collections.Counter(s)\n",
    "        aflag = False\n",
    "        lflag = False\n",
    "        if d['A'] < 2:\n",
    "            aflag = True\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == 'L' and i < len(s) - 2:\n",
    "                if s[i + 1] == 'L' and s[i + 2] == 'L':\n",
    "                    lflag = True\n",
    "                    break\n",
    "        return aflag and (not lflag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return 'LLL' not in s and s.count('A') < 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and s.count('LLL') ==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        a_count=0\n",
    "        l_count=0\n",
    "        for c in s:\n",
    "            if c=='L':\n",
    "                l_count+=1\n",
    "                if l_count>=3:\n",
    "                    return False\n",
    "            else:\n",
    "                l_count=0               \n",
    "                if c=='A':\n",
    "                    a_count+=1\n",
    "                    if a_count>=2:\n",
    "                        return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return not 'LLL' in s and s.count('A') < 2\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if(s.count(\"A\")<2 and s.count(\"LLL\")==0):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and 'LLL' not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        late_count = 0\n",
    "\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                absent += 1\n",
    "                late_count = 0\n",
    "            elif i == 'L':\n",
    "                late_count += 1\n",
    "            elif late_count != 0:\n",
    "                late_count =0\n",
    "            \n",
    "            if absent == 2 or late_count == 3:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def checkRecord(self, s: str) -> bool:\r\n",
    "        s_list = list(s)\r\n",
    "        if s_list.count('A') < 2 and 'LLL' not in s:\r\n",
    "            return True\r\n",
    "        else: return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count('A')<2 and 'LLL' not in s:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        k=s.count(\"A\")\n",
    "        n=len(s)\n",
    "        if n==2 and k==2:\n",
    "            return False\n",
    "        elif n<=1:\n",
    "            return True\n",
    "        for i in range (n-2):\n",
    "            if s[i]==s[i+1]==s[i+2]==\"L\" or  k>=2:\n",
    "                return False\n",
    "        return True\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        l=0\n",
    "        a=0\n",
    "        for i in s:\n",
    "            if l>=3:\n",
    "                return False\n",
    "            if i==\"A\":\n",
    "                a+=1\n",
    "                l=0\n",
    "            elif i==\"L\":\n",
    "                l+=1\n",
    "            else:\n",
    "                l=0\n",
    "        if a<2 and l<3:\n",
    "            return True\n",
    "        else:\n",
    "            return False    \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and 'LLL' not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absents = lates = 0\n",
    "        for i, c in enumerate(s):\n",
    "            if c == \"A\":\n",
    "                absents += 1\n",
    "                if absents >= 2:\n",
    "                    return False\n",
    "            if c == \"L\":\n",
    "                lates += 1\n",
    "                if lates >= 3:\n",
    "                    return False\n",
    "            else:\n",
    "                lates = 0\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        Late = 0\n",
    "        if s[0] == 'A':\n",
    "            absent += 1\n",
    "        for i in range(1,len(s)):\n",
    "            if s[i] == 'A':\n",
    "                absent += 1\n",
    "                if absent >= 2:\n",
    "                    return False\n",
    "            elif s[i] == 'L' and s[i-1] == 'L':\n",
    "                Late += 1\n",
    "                if Late >= 2:\n",
    "                    return False\n",
    "            else:\n",
    "                Late = 0\n",
    "        return True\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        count1=0\n",
    "        count2=0\n",
    "        n=len(s)\n",
    "        if n==1:\n",
    "            return True\n",
    "        if n==2:\n",
    "            if s[0]==s[1]=='A':\n",
    "                return False\n",
    "            return True\n",
    "        if n>2:\n",
    "            if s[0]=='A':\n",
    "                count1+=1\n",
    "            if s[1]=='A':\n",
    "                count1+=1 \n",
    "            for i in range(2,n):\n",
    "                if s[i]=='A':\n",
    "                    count1+=1\n",
    "                if s[i-2]==s[i-1]==s[i]=='L':\n",
    "                    count2+=1\n",
    "            if count1<2 and count2==0:\n",
    "                return True\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        list_s=list(s)\n",
    "        count=list_s.count('A')\n",
    "        if count>=2 or 'LLL' in s:\n",
    "            return False\n",
    "        if count<2 and 'LLL' not in s:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A') < 2 and ('LLL' not in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        A_count=0\n",
    "        for i in range(len(s)):\n",
    "            if s[i]=='A':\n",
    "                A_count+=1\n",
    "                if A_count==2:\n",
    "                    return False\n",
    "            if i<len(s)-2 and s[i]=='L' and s[i+1]=='L' and s[i+2]=='L':\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return s.count('A')<2 and 'LLL' not in s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        return not 'LLL' in s and s.count('A') < 2\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absent = 0\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == 'A':\n",
    "                absent += 1\n",
    "                if absent == 2: return False\n",
    "            elif s[i] == 'L':\n",
    "                if s[i:i+3] == 'LLL': return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        if s.count(\"A\") > 1 or \"LLL\" in s:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkRecord(self, s: str) -> bool:\n",
    "        absents = 0\n",
    "        lates = 0\n",
    "        #reward = True\n",
    "        for ch in s:\n",
    "            if ch == 'A':\n",
    "                absents += 1\n",
    "                if absents >= 2:\n",
    "                    return False\n",
    "            if ch == 'L':\n",
    "                lates += 1\n",
    "                if lates >= 3:\n",
    "                    return False\n",
    "            else:\n",
    "                lates = 0\n",
    "\n",
    "        return True"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
